<div ng-controller="Provider_ToProviderDetailC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 ng-if="orderdata.From != 3" class="m-n font-thin h3">入库单详情</h1>
        <h1 ng-if="orderdata.From == 3" class="m-n font-thin h3">冲红单详情</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="form-group">
                                <label>收货仓库</label>
                                <!--<select required class="form-control cangku" ng-model="orderdata.Provider" ng-options="value.Name for value in cangku1" ng-change="removeStockGoods()"></select>-->
                                <input type="text" class="form-control" disabled ng-model="orderdata.Provider.Name">
                            </div>
                            <div class="form-group">
                                <label>每吨运费</label>
                                <input disabled ng-model="orderdata.DeliveryPrice" type="number" min="0" class="form-control">
                            </div>
                            <div class="form-group">
                                <label>备注(非必填)</label>
                                <input ng-model="orderdata.Remark" disabled type="text" class="form-control" placeholder="备注信息" maxlength="100">
                            </div>
                        </div>
                        <div class="container-fluid bg-light lter">
                            <div class="row" style="height: 40px;">
                                <div class="col-xs-12 col-md-12 text-left">
                                    <strong style="display: inline-block;line-height: 40px">入库商品列表</strong>
                                </div>
                            </div>
                        </div>
                        <div class="container-fluid" style="padding-top: 10px">
                            <div class="panel panel-default" ng-repeat="item in orderdata.StockGoods" style="margin-bottom: 10px">
                                <div class="panel-heading">
                                    <div>品牌：{{item.Commodity.Brand}}</div>
                                </div>
                                <div class="panel-body">
                                    <div class="row">
                                        <div class="col-xs-9 col-md-9">
                                            <div>名称/材质/规格：{{item.Commodity.Name}}/{{item.Commodity.Standard}}/{{item.Commodity.Format}}</div>
                                            <!--<div style="margin-bottom: 5px">单价    ：<input type="number" min="0" ng-model="item.Price">/t</div>-->
                                            <!--<div style="margin-bottom: 5px">数量    ：<input type="number" min="0" ng-model="item.Count"></div>-->
                                            <!--<div style="margin-bottom: 5px">总质量  ：<input type="number" min="0" ng-model="item.TotalWeight"></div>-->
                                            <!--<div style="margin-bottom: 5px">不含税价：<input type="number" min="0" ng-model="item.NormPrice"></div>-->
                                            <div style="margin-bottom: 5px">单价    ：{{item.Price | number:2}}/t</div>
                                            <div style="margin-bottom: 5px">数量    ：{{item.Count}}</div>
                                            <div style="margin-bottom: 5px">总质量  ：{{item.TotalWeight | number:3}}</div>
                                            <div style="margin-bottom: 5px">不含税价：{{item.NormPrice | number:2}}</div>
                                            <!--<div>总价：{{item.Count}}*{{item.Price}}*{{item.Weight}}t={{item.Count*item.Price*item.Weight.toFixed(2)}}</div>-->
                                            <!--<div>总价：{{item.Count}}*{{item.Price}}*{{item.Weight}}t={{(item.Count*item.Price*item.Weight) | number:2}}</div>-->
                                        </div>
                                        <!--<div class="col-xs-3 col-md-3" style="text-align: center;">-->
                                            <!--<button type="button" class="btn btn-sm btn-default" ng-click="Countadd(item)" style="margin: 5px">-->
                                                <!--<i class="fa fa-plus text"></i>-->
                                            <!--</button>-->
                                            <!--<button type="button" class="btn btn-sm btn-default" ng-click="Countdeduct(item)" style="margin: 5px">-->
                                                <!--<i class="fa fa-minus text"></i>-->
                                            <!--</button>-->
                                            <!--<button type="button" class="btn btn-sm btn-danger" ng-click="deduct(item)" style="margin: 5px">-->
                                                <!--删除-->
                                            <!--</button>-->
                                        <!--</div>-->
                                    </div>
                                </div>
                            </div>
                            <div class="row text-center" style="height: 40px;">
                                <a>
                                    <div ng-if="orderdata.State != 1 && orderdata.From != 3" class="col-xs-6 col-md-6" style="display: inline-block;line-height: 100%;height: 100%;padding: 0px">
                                        <button type="button" style="width: 100%;height: 100%" class="btn btn-danger" ng-click="rush()">冲红</button>
                                    </div>
                                    <div class="col-xs-6 col-md-6" style="display: inline-block;line-height: 100%;height: 100%;padding: 0px">
                                        <button type="button" style="width: 100%;height: 100%" class="btn btn-default" ng-click="abolish()">返回列表页</button>
                                    </div>
                                    <!--<div class="col-xs-6 col-md-6" style="display: inline-block;line-height: 100%;height: 100%;padding: 0px">-->
                                        <!--<button type="button" style="width: 100%;height: 100%" class="btn btn-success" ng-disabled="form.$invalid" ng-click="ordersub()">提交入库单</button>-->
                                    <!--</div>-->
                                </a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')
            //创建采购单控制器
            .controller("Provider_ToProviderDetailC", function ($scope, $state, $stateParams, $http) {
//                $scope.id = JSON.parse($stateParams.id);
                console.log($stateParams.id);

                //获取详情方法
                $http({
                    url: "../api/Provider/GetWarehouseEntry?warehouseEntryId=" + $stateParams.id,
                    method: "GET"
                })
                        .then(function (res) {
                            if (res.State <= 0) {
                                alert(res.Msg);
                            } else {
                                $scope.orderdata = res.data.Data;
                                console.log(res.data.Data);
                            }
                        })
                        .then(function (error) {
                            if (error) {
                                console.log("error");
                            }
                        });
                $scope.rush = function(){
                    if (confirm("确定将此入库单冲红？")) {
                        $http({
                            url: "../api/Provider/OffsetWarehouseEntry?id=" + $stateParams.id,
                            method: "POST"
                        })
                                .then(function (res) {
                                    alert("冲红成功");
                                    $state.go('app.Provider_ToProviderList');
                                })
                                .then(function (error) {
                                    if (error) {
                                        console.log("error");
                                    }
                                });
                    } else {
                        console.log("操作取消");
                    }
                };

                //提交采购单
                $scope.ordersub = function () {
                        $http.post('../api/Provider/CreateAndRunEntry', $scope.orderdata)
                                .success(function (res) {
                                    if (res.State <= 0) {
                                        alert(res.Msg);
                                    } else {
                                        alert("添加成功");
                                        $state.go('app.Provider_DepotCommodityList' , {id:$scope.orderdata.ProviderId,Name:$scope.orderdata.Provider.Name,type:1});
                                    }
                                });
                    };
//                返回上一页
                $scope.abolish = function () {
                    $state.go('app.Provider_ToProviderList');
                };
            })
</script>